/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbenglish_client;

import bllInterface.BLLFactory;
import bllfactory.SBLLFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import tbenglish_client.form.*;
import utils.DefaultPort;

/**
 *
 * @author salm
 */
public class TBEnglish_Client {

    private static String BLLHost;
    
    private static void readHost()
    {
        // NEED TABLE
        try
        {
            Properties p = new Properties();
            p.load(new FileInputStream("src\\RMIConfig.ini"));
            
            BLLHost = p.getProperty("BLLHost");
        }
        catch (IOException ioEx)
        {
            BLLHost = "rmi://localhost";
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        try
        {
            readHost();
            BLLFactory bllFact = (BLLFactory) Naming.lookup(String.format("%s:%d/%s", BLLHost, DefaultPort.getInstance().getBLLPort(), "BLLFactory"));
            SBLLFactory.initInstance(bllFact);
            try 
            {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            }
            catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
                    java.util.logging.Logger.getLogger(userInfo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new loginForm().setVisible(true);
                }
            });
        } catch (RemoteException | NotBoundException | MalformedURLException ex) {
            Logger.getLogger(TBEnglish_Client.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(null, "Connection error!!");
        }
    }
}